package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysAppointmentMapper;
import com.ruoyi.system.domain.SysAppointment;
import com.ruoyi.system.service.ISysAppointmentService;
import com.ruoyi.system.service.ISysAppointmentSlotService;

/**
 * 预约信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-09
 */
@Service
public class SysAppointmentServiceImpl implements ISysAppointmentService 
{
    @Autowired
    private SysAppointmentMapper sysAppointmentMapper;

    @Autowired
    private ISysAppointmentSlotService sysAppointmentSlotService;

    /**
     * 查询预约信息
     * 
     * @param appointmentId 预约信息主键
     * @return 预约信息
     */
    @Override
    public SysAppointment selectSysAppointmentByAppointmentId(Long appointmentId)
    {
        return sysAppointmentMapper.selectSysAppointmentByAppointmentId(appointmentId);
    }

    /**
     * 查询预约信息列表
     * 
     * @param sysAppointment 预约信息
     * @return 预约信息
     */
    @Override
    public List<SysAppointment> selectSysAppointmentList(SysAppointment sysAppointment)
    {
        return sysAppointmentMapper.selectSysAppointmentList(sysAppointment);
    }

    /**
     * 新增预约信息
     * 
     * @param sysAppointment 预约信息
     * @return 结果
     */
    @Override
    public int insertSysAppointment(SysAppointment sysAppointment)
    {
        sysAppointment.setCreateTime(DateUtils.getNowDate());
        int rows = sysAppointmentMapper.insertSysAppointment(sysAppointment);
        if (rows > 0 && sysAppointment.getSlotId() != null) {
            sysAppointmentSlotService.incrementBookedCount(sysAppointment.getSlotId());
        }
        return rows;
    }

    /**
     * 修改预约信息
     * 
     * @param sysAppointment 预约信息
     * @return 结果
     */
    @Override
    public int updateSysAppointment(SysAppointment sysAppointment)
    {
        sysAppointment.setUpdateTime(DateUtils.getNowDate());
        return sysAppointmentMapper.updateSysAppointment(sysAppointment);
    }

    /**
     * 批量删除预约信息
     * 
     * @param appointmentIds 需要删除的预约信息主键
     * @return 结果
     */
    @Override
    public int deleteSysAppointmentByAppointmentIds(Long[] appointmentIds)
    {
        return sysAppointmentMapper.deleteSysAppointmentByAppointmentIds(appointmentIds);
    }

    /**
     * 删除预约信息信息
     * 
     * @param appointmentId 预约信息主键
     * @return 结果
     */
    @Override
    public int deleteSysAppointmentByAppointmentId(Long appointmentId)
    {
        return sysAppointmentMapper.deleteSysAppointmentByAppointmentId(appointmentId);
    }

    @Override
    public int updateAppointmentStatus(Long appointmentId, String status) {
        return sysAppointmentMapper.updateAppointmentStatus(appointmentId, status);
    }
}
